package com.bleeth.fx.view.demo7;

import com.bleeth.fx.component.MButton;
import com.bleeth.fx.helper.SStyleHelper;
import com.bleeth.fx.helper.ThemeHelper;
import com.bleeth.fx.layout.BaseBuilder;
import com.bleeth.fx.layout.GirdBuilder;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @author ：Bleeth
 * @date ：2022-03-15
 * @description：
 */
public class LoginView extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {


        GirdBuilder gBer = GirdBuilder.create()
                .addVBuilder(
                        BaseBuilder.create().setId("row-title").setHeight(50D),
                        BaseBuilder.create().setId("empty").setHeight(20D),
                        BaseBuilder.create().setId("row-username").setHeight(30D).setSpacing(20D),
                        BaseBuilder.create().setHeight(40D),
                        BaseBuilder.create().setId("row-password").setHeight(30D).setSpacing(20D),
                        BaseBuilder.create().setHeight(40D),
                        BaseBuilder.create().setId("row-login").setHeight(40D).setSpacing(20D)
                )
                .addRow("row-title", BaseBuilder.create().setSpan(1).setPos(Pos.CENTER))
                .addCell(0, "title", new Label("欢迎大家的到来"))

                .addRow("row-username", BaseBuilder.create().setSpan(1), BaseBuilder.create().setWidth(80D).setPos(Pos.CENTER_RIGHT),
                        BaseBuilder.create().setWidth(300D).setPos(Pos.CENTER_LEFT), BaseBuilder.create().setSpan(1))
                .addCell(1, "label-username", new Label("用户名"))
                .coverCell(2, "input-username", new TextField(""))

                .addRow("row-password", BaseBuilder.create().setSpan(1), BaseBuilder.create().setWidth(80D).setPos(Pos.CENTER_RIGHT),
                        BaseBuilder.create().setWidth(300D).setPos(Pos.CENTER_LEFT), BaseBuilder.create().setSpan(1))
                .addCell(1, "label-password", new Label("密  码"))
                .coverCell(2, "input-password", new TextField(""))

                .addRow("row-login", BaseBuilder.create().setSpan(1).setPos(Pos.CENTER), BaseBuilder.create().setWidth(150D).setPos(Pos.CENTER), BaseBuilder.create().setSpan(1).setPos(Pos.CENTER))
                .coverCell(1, "btn-login", MButton.builder().type(ThemeHelper.PRIMARY).text("登  录").build().make());

        VBox mainBox = gBer.build();

        setStyle(gBer);
        setAction(gBer);

        Scene scene = new Scene(mainBox, 600D, 400D);
        mainBox.prefHeightProperty().bind(scene.heightProperty());
        mainBox.prefWidthProperty().bind(scene.widthProperty());
        primaryStage.setResizable(false);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void setStyle(GirdBuilder gBer) {
        VBox root = gBer.build();


        Region titleRegion = gBer.getRegion("title");
        Region labelUsernameRegion = gBer.getRegion("label-username");
        Region inputUsernameRegion = gBer.getRegion("input-username");

        Region labelPasswordRegion = gBer.getRegion("label-password");
        Region inputPasswordRegion = gBer.getRegion("input-password");
        Region btnPasswordRegion = gBer.getRegion("btn-login");

        SStyleHelper.node(titleRegion)
                .addStyle("-fx-font-size", "18")
                .apply();

        SStyleHelper.node(labelUsernameRegion)
                .addStyle("-fx-font-size", "18")
                .apply();

        SStyleHelper.node(labelPasswordRegion)
                .addStyle("-fx-font-size", "18")
                .apply();


    }

    public void setAction(GirdBuilder gBer) {
        Region btnLogin = gBer.getRegion("btn-login");
        btnLogin.setOnMouseClicked(event -> {
            System.err.println("login...");
        });

    }


    public static void main(String[] args) {
        launch(args);
    }

}
